package iot.wlink.network.protocols.mqtt;

import iot.wlink.network.devices.bean.Identity;
import lombok.extern.slf4j.Slf4j;
import net.dreamlu.iot.mqtt.core.server.IMqttServerAuthHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author : willian fu
 * @date : 2021/8/22
 * mqtt身份认证
 */
@Slf4j
@Component
public class MqttDeviceAuthenticationHandler implements IMqttServerAuthHandler {

    @Autowired
    private MqttDeviceManager manager;

    @Override
    public boolean authenticate(String uid, String tid, String secret) {
        try {
           // manager.authentication(Identity.builder().uid(uid).tid(Long.parseLong(tid)).secret(secret).build());
        } catch (Exception e) {
            log.error("设备[{}, {}, {}]鉴权失败", uid, tid, secret);
            return false;
        }
        return true;
    }
}
